/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.admin.controller.agreement;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shop.cereshop.admin.service.agreement.AgreementService;
import com.shop.cereshop.commons.domain.agreement.Agreement;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 协议表
 * </p>
 *
 * @author
 * @date 2025-07-29
 */
@Slf4j
@RestController
@RequestMapping("/agreement")
@Api(value = "Agreement", tags = "协议表")
public class AgreementController {

    @Resource
    private AgreementService agreementService;

    /**
     * 根据id查询 协议表
     *
     * @param id id
     * @return 协议内容
     */
    @GetMapping("getById")
    @ApiOperation(value = "根据id查询协议表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "主键id", value = "id", required = true, dataType = "Long", paramType = "query")
    })
    public Result<Agreement> getById(Long id) {
        /*
          1 用户协议
          2 隐私政策
          3 招住类型
          4 合作流程
         */
        return new Result(agreementService.getById(id));
    }

    @GetMapping("getPage")
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "页码", value = "pageNum", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "每页数量", value = "pageSize", required = true, dataType = "Integer", paramType = "query")
    })
    public Result<IPage<Agreement>> getPage(Integer pageNum, Integer pageSize) {
        return new Result(agreementService.getPage(pageNum, pageSize));
    }

    @PutMapping
    @ApiOperation(value = "保存")
    public Result save(Agreement agreement) {
        return new Result(agreementService.save(agreement));
    }

    @PostMapping
    @ApiOperation(value = "更新")
    public Result update(Agreement agreement) {
        UpdateWrapper<Agreement> updateWrapper = new UpdateWrapper<>();
        updateWrapper.setEntity(agreement);
        return new Result(agreementService.update(updateWrapper));
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "主键id", value = "id", required = true, dataType = "Long", paramType = "path")
    })
    public Result delete(@PathVariable Long id) {
        return new Result(agreementService.removeById(id));
    }

}
